import numpy as np


x = np.array([
    [0.93,0.95],
    [0.91,0.93],
    [0.89,0.95],
    [0.95,0.91],
    [-1.89,-2.14],
    [-1.92,-2.35],
    [-1.93,-2.46],
    [-1.55,-2.77]
])

y = np.array([
    [1],
    [1],
    [1],
    [1],
    [0],
    [0],
    [0],
    [0]
])

def sigmoid(x):
    return 1/(1+np.exp(-x))

def sigmoid_dao(x):
    return x*(1-x)
def test(W0,W1):
    x1 = np.array([
        [0.99,0.75],
        [0.81,0.73],
        [-2.81,-4.6],
        [-1.71,-2.31]
    ])
    l1_test = sigmoid(np.matmul(x1,W0))
    y_test = sigmoid(np.matmul(l1_test,W1))
    print(y_test)

W0 = np.random.random((2,4))
W1 = np.random.random((4,1))

for i in range(100):

    #print(x.shape,W0.shape,W1.shape,y.shape)
    l1 = sigmoid(np.matmul(x,W0))
    y_ = sigmoid(np.matmul(l1,W1))
    # out loss
    loss = y-y_
    if i%20 == 0:
        print(np.mean(np.abs(loss)))
        test(W0,W1)
    #L1 delta
    l1_delta = loss * sigmoid_dao(y_)
    #l1 loss
    l1_loss = np.matmul(l1_delta,W1.T)
    #l0 loss
    l0_delta = l1_loss * sigmoid_dao(l1)

    W1 += np.matmul(l1.T,l1_delta)
    W0 += np.matmul(x.T,l0_delta)

    #print(l1_error)
